package com.yq.cp.utils;

import com.yq.cp.entity.data.dto.IndexDataSqlDto;
import com.yq.cp.entity.data.dto.IndexSqlDataViewDto;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 单位转换util
 */
public class UnitUtil {

    public static String unit(BigDecimal val,Integer type){

        Map<Integer, String> map = new HashMap<>();
        map.put(100,"Kw");
        map.put(101,"m³");
        map.put(102,"m³");
        map.put(103,"m³");
        map.put(200,"Gj");
        map.put(201,"Gj");
        map.put(202,"t");
        map.put(203,"m³");
        map.put(204,"Kw");
        map.put(300,"t");
        map.put(301,"t");
        map.put(302,"t");
        map.put(303,"t");
        map.put(304,"颗");


        int j = val.compareTo(new BigDecimal(100000000));
        if (j==1||j==0){
            String s = val.divide(new BigDecimal(100000000), 2, BigDecimal.ROUND_CEILING).toString();
            return s+"亿"+map.get(type);
        }

        int i = val.compareTo(new BigDecimal(10000));
        //大于一万的情况
        if (i==1||i==0){
            //取两位小数
            String s = val.divide(new BigDecimal(10000), 2, BigDecimal.ROUND_CEILING).toString();
            return s+"万"+map.get(type);
        }

        String s = val.setScale(2, BigDecimal.ROUND_DOWN).toString();
        return s+map.get(type);
    }

    public static String realUnit(BigDecimal val,Integer type){
        Map<Integer, String> map = new HashMap<>();
        map.put(100,"Kwh");
        map.put(101,"m³/h");
        map.put(102,"m³/h");
        map.put(103,"m³/h");
        map.put(200,"Gj/H");
        map.put(201,"Gj/H");
        map.put(202,"t/h");
        map.put(203,"m³/h");
        map.put(204,"Kwh");

        int j = val.compareTo(new BigDecimal(100000000));
        if (j==1||j==0){
            String s = val.divide(new BigDecimal(100000000), 2, BigDecimal.ROUND_CEILING).toString();
            return s+"亿"+map.get(type);
        }

        int i = val.compareTo(new BigDecimal(10000));
        //大于一万的情况
        if (i==1||i==0){
            //取两位小数
            String s = val.divide(new BigDecimal(10000), 2, BigDecimal.ROUND_CEILING).toString();
            return s+"万"+map.get(type);
        }

        String s = val.setScale(2, BigDecimal.ROUND_DOWN).toString();
        return s+map.get(type);


    }

    public static List<IndexSqlDataViewDto> unit2(List<IndexSqlDataViewDto> val){
        val.forEach(o ->{
            List<IndexDataSqlDto> list = o.getList();
            list.forEach(i ->{
                BigDecimal value = i.getValue().divide(new BigDecimal(10000), 2, BigDecimal.ROUND_CEILING);
                i.setValue(value);
            });
            o.setList(list);
        });
        return val;
    }



}
